package com.whatocean.controller;


import com.whatocean.controller.result.Result;
import com.whatocean.domain.Account;
import com.whatocean.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController /* @Controller + @ResponseBody*/
@RequestMapping("/account")
public class AccountController {


    @Autowired
    private AccountService accountservice;

    @RequestMapping("/add")
    public Result addAccount (Account account){
        try {
            accountservice.addAccount(account);
            return new Result(true,"新增成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"新增失败");
    }
    @RequestMapping("/del")
    public Result delAccount (Integer id){
        try {
            if (id != null){
                accountservice.delAccount(id);
                return new Result(true,"删除成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"删除失败");
    }
    @RequestMapping("/update")
    public Result updateAccount (Account account){
        try {
                accountservice.updateAccount(account);
                return new Result(true,"修改成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result(false,"修改失败");
    }

}
